package org.jeecg.modules.job.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.job.bms.entity.*;
import org.jeecg.modules.job.bms.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/bms")
@Api(tags="移动端基础信息管理模块")
@Slf4j
public class BmsController {

    @Resource
    private IBmsIndustryService industryService;
    @Resource
    private IBmsPostCategoryService postInfoService;
    @Resource
    private IBmsWelfareService welfareService;
    @Resource
    private IBmsCityService cityService;
    @Resource
    private IBmsSchoolService schoolService;

    /**
     * 查询行业信息列表
     */
    @RequestMapping(value = "/getIndustryList",method = RequestMethod.GET)
    @ApiOperation(value = "查询行业信息列表", notes = "查询行业信息列表")
    public Result<Object> getIndustryList(String pid) {
        List<BmsIndustry> list;
        if (pid!=null){
            list= industryService.list(new QueryWrapper<>(new BmsIndustry().setPid(pid).setStatus(1)));
        }else{
            //查询父类
            list= industryService.list(new QueryWrapper<>(new BmsIndustry().setPid("0").setStatus(1)));
            //查询之类
            for (int i=0;i<list.size();i++){
                list.get(i).setChild( industryService.list(new QueryWrapper<>(new BmsIndustry().setPid(list.get(i).getId()).setStatus(1))));
            }
        }
        return Result.ok(list);
    }

    /**
     * 查询职位信息列表
     */
    @RequestMapping(value = "/getPostList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位信息列表", notes = "查询职位信息列表")
    public Result<Object> getPostList(String pid) {
        BmsPostCategory param=new BmsPostCategory();
        param.setStatus(1);
        List<BmsPostCategory> list;
        List<BmsPostCategory> child;
        if (pid!=null){
            param.setPid(pid);
            list= postInfoService.list(new QueryWrapper<>(param));
        }else{
            //查询父类
            param.setPid("0");
            list= postInfoService.list(new QueryWrapper<>(param));
            //查询之类
            for (int i=0;i<list.size();i++){
                param.setPid(list.get(i).getId());
                child=postInfoService.list(new QueryWrapper<>(param));
                for (int j=0;j<child.size();j++){
                    param.setPid(child.get(j).getId());
                    child.get(j).setChild(postInfoService.list(new QueryWrapper<>(param)));
                }
                list.get(i).setChild(child);
            }
        }
        return Result.ok(list);
    }


    /**
     * 查询职位列表
     */
    @RequestMapping(value = "/getHotPostList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位列表", notes = "查询职位列表")
    public Result<Object> getHotPostList(BmsPostCategory param) {
        param.setIfHot(1);
        param.setStatus(1);
        List<BmsPostCategory> list= postInfoService.list(new QueryWrapper<>(param));
        return Result.ok(list);
    }


    /**
     * 查询职位列表
     */
    @RequestMapping(value = "/getPostPageList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位列表", notes = "查询职位列表")
    public Result<Object> getPostPageList(BmsPostCategory param,
                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize
                                          ) {
        IPage<BmsPostCategory> pageInfo= postInfoService.page(new Page<>(pageNo, pageSize),new QueryWrapper<>(param).orderByAsc("sort"));
        return Result.ok(pageInfo);
    }


    /**
     * 查询福利信息表
     */
    @RequestMapping(value = "/getWelfareList",method = RequestMethod.GET)
    @ApiOperation(value = "查询福利信息表", notes = "查询福利信息表")
    public Result<Object> getWelfareList() {
        BmsWelfare param=new BmsWelfare();
        param.setStatus(1);
        List<BmsWelfare> list = welfareService.list(new QueryWrapper<>(param));
        return Result.ok(list);
    }

    /**
     * 查询所有城市列表
     */
    @RequestMapping(value = "/getCityList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有城市列表", notes = "查询所有城市列表")
    public Result<Object> getCityList() {
        BmsCity cityParam=new BmsCity();
        Map<String,Object> result;
        result= cityService.findListForApp(cityParam);
        return Result.ok(result);
    }

    /**
     * 查询所有城市列表
     */
    @RequestMapping(value = "/getHotCityList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有城市列表", notes = "查询所有城市列表")
    public Result<Object> getHotCityList() {
        List<BmsCity> result= cityService.list(new QueryWrapper<>(new BmsCity().setIfHot(1)));
        return Result.ok(result);
    }

    /**
     * 查询学校列表
     */
    @RequestMapping(value = "/getSchoolList",method = RequestMethod.GET)
    @ApiOperation(value = "查询学校列表", notes = "查询学校列表")
    public Result<Object> getSchoolList(BmsSchool param,
                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                        @RequestParam(name="pageSize", defaultValue="20") Integer pageSize
    ) {
        IPage<BmsSchool> pageInfo= schoolService.page(new Page<>(pageNo,pageSize),new QueryWrapper<>(param));
        return Result.ok(pageInfo);
    }

}